#include "form1.h"
#include "ui_form1.h"
#include <QString>

Form1::Form1(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form1)
{
    ui->setupUi(this);
}

Form1::~Form1()
{
    delete ui;
}

void Form1::on_pushButton_clicked() //сложение
{
x1.re=ui->lineEdit->text().toDouble();
x1.im=ui->lineEdit_2->text().toDouble();
x2.re=ui->lineEdit_4->text().toDouble();
x2.im=ui->lineEdit_3->text().toDouble();
otvet=x1+x2;
QString a;

ui->lineEdit_6->setText(a.setNum(otvet.re));
ui->lineEdit_5->setText(a.setNum(otvet.im));
}
void Form1::on_pushButton_2_clicked() //Вычитание
{
x1.re=ui->lineEdit->text().toDouble();
x1.im=ui->lineEdit_2->text().toDouble();
x2.re=ui->lineEdit_4->text().toDouble();
x2.im=ui->lineEdit_3->text().toDouble();
otvet=x1-x2;
QString a;

ui->lineEdit_6->setText(a.setNum(otvet.re));
ui->lineEdit_5->setText(a.setNum(otvet.im));
}


void Form1::on_pushButton_3_clicked() //Умножение
{
x1.re=ui->lineEdit->text().toDouble();
x1.im=ui->lineEdit_2->text().toDouble();
x2.re=ui->lineEdit_4->text().toDouble();
x2.im=ui->lineEdit_3->text().toDouble();
otvet=x1*x2;
QString a;

ui->lineEdit_6->setText(a.setNum(otvet.re));
ui->lineEdit_5->setText(a.setNum(otvet.im));
}
void Form1::on_pushButton_4_clicked() //Деление
{
x1.re=ui->lineEdit->text().toDouble();
x1.im=ui->lineEdit_2->text().toDouble();
x2.re=ui->lineEdit_4->text().toDouble();
x2.im=ui->lineEdit_3->text().toDouble();
otvet.re=((x1.re*x2.re)+(x1.im*x2.im))/(x2.re*x2.re+x2.im*x2.im);//ответ Реальная часть
otvet.im=((x2.re*x1.im)-(x2.im*x1.re))/(x2.re*x2.re+x2.im*x2.im);//оответ Мнимая часть
QString a;

ui->lineEdit_6->setText(a.setNum(otvet.re));
ui->lineEdit_5->setText(a.setNum(otvet.im));
}
void Form1::on_pushButton_5_clicked() //Модуль
{
x1.re=ui->lineEdit->text().toDouble();
x1.im=ui->lineEdit_2->text().toDouble();
x2.re=ui->lineEdit_4->text().toDouble();
x2.im=ui->lineEdit_3->text().toDouble();
otvet=sqrt (x1.re * x1.re + x1.im * x1.im);
QString a;

ui->lineEdit_6->setText(a.setNum(otvet.re));
ui->lineEdit_5->setText(a.setNum(otvet.im));
}

